//
//  HPYMinViewController.swift
//  SwiftVVBo
//
//  Created by hepeiyong on 16/8/9.
//  Copyright © 2016年 hpyhn. All rights reserved.
//

import UIKit
import SVProgressHUD
class HPYMinViewController: UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // 实例化自定义tabBar
        let tabBar = HPYtabBar()
        // 设置代理
        tabBar.hmDelegate = self
        // 只读属性
        //self.tabBar
        // 通过kvc 给只读属性赋值
        setValue(tabBar, forKey: "tabBar")
        // 首页
        addChildViewController(HPYHomeViewController(), imgName: "tabbar_home", title: "首页")
        // 消息
        addChildViewController(HPYMessageViewController(), imgName: "tabbar_message_center", title: "消息")
        // 发现
        addChildViewController(HPYDiscoverViewController(), imgName: "tabbar_discover", title: "发现")
        // 我
        addChildViewController(HPYProfileViewController(), imgName: "tabbar_profile", title: "我")

    }
    /**
     添加子控制器
     - parameter vc:      控制器
     - parameter imgName: 图片名称
     - parameter title:   title
     */
    func addChildViewController(vc: UIViewController, imgName: String, title: String){
        // 设置tilte
        //        vc.navigationItem.title = title
        //        vc.tabBarItem.title = title
        vc.title = title
        // 设置title
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        // 设置图片
        vc.tabBarItem.image = UIImage(named: imgName)
        // AlwaysOriginal 图片渲染方式
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        // 添加子控制器
        addChildViewController(UINavigationController(rootViewController: vc))
    }
}

extension HPYMinViewController: HPYTabBarDelegate{
    func tabBarButtonClick() {
        printLog("撰写按钮点击啦")
        //如果没有登录提示请先登录
        if !HPYUserAccountViewModel.sharedTools.isLogin {
            SVProgressHUD.showInfoWithStatus("请先登录")
            return
        }
        self.presentViewController(UINavigationController(rootViewController: HPYComposeViewController()), animated: true, completion: nil)

    }
}